<?php

class PasswordTable extends Doctrine_Table {
	public function findOneByOwnerAndDomain($owner, $domain) {
		return $this->createQuery('p')
			->where('p.owner_id = ?', $owner->id)
			->andWhere('p.domain = ?', $domain)
			->fetchOne();
	}

	public function findOrCreateOneByOwnerAndDomain($owner, $domain) {
		$pw = $this->findOneByOwnerAndDomain($owner, $domain);
		if(!$pw) {
			$pw = new Password();
			$pw->Owner = $owner;
			$pw->domain = $domain;
		}
		return $pw;
	}

	public function deleteOneByOwnerAndDomain($owner, $domain) {
		$pw = $this->findOneByOwnerAndDomain($owner, $domain);
		if($pw) $pw->delete();
	}
}
